package com.lsf.action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.lsf.po.User;
import com.lsf.service.UserService;

/**

 * 创建日期：2013-3-8下午08:07:14

 * 修改日期：

 * 作者：刘帅飞

 */

public class LoginAction extends ActionSupport{

	private String username;
	private String password;
	private UserService userService;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public String execute() throws Exception {
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		if(userService.isLogin(user)) {
			Map session = ActionContext.getContext().getSession();
			session.put("username", username);			
			session.put("theBiggestMessageId", 0); /*LoadPubMessageAction备用*/
			
			/*Calendar calen1 = Calendar.getInstance(); 	calen1.getTime();	System.out.println("first"+calen1); 
			calen1.add(Calendar.SECOND, -5);				System.out.println("second"+calen1);
			
			Calendar calen = Calendar.getInstance(); 获取Calendar实例	
			calen.getTime();	calen获取当前时间
			calen.add(Calendar.SECOND, -5);		当前时间减去5秒		
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
			String time = df.format(calen);	把calen转化为String类型的time
			Timestamp nowMinusFiveSecond = Timestamp.valueOf(time);	把string类型的time转化为Timestamp类型
			 														获得比当前时间早5秒的nowMinusFiveSecond*/
			
			
			this.addActionMessage("登录成功!");
			return SUCCESS;
		} else {
			this.addActionMessage("登录失败!");
			return INPUT;
		}
	}

}
